package task;

import java.util.concurrent.Callable;

/**
 * 带返回结果的任务，返回一个Callable
 * @author wxhntmy
 */
public class ReturnResultTaskCallable implements Callable<Object> {

    /**
     * 任务名称
     */
    private String name;

    /**
     * 构造函数
     * @param name 任务名称
     */
    public ReturnResultTaskCallable(String name) {
        this.name = name;
    }

    @Override
    public Object call() throws Exception {
        System.out.println(this.toString() + " is running!");

        System.out.println("Asynchronous Callable");

        try {
            //让任务执行慢点
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println(this.toString() + " is end!");

        return "Callable Result";
    }

    /**
     * 获取任务名称
     * @return 任务名称
     */
    public String getName() {
        return name;
    }

    @Override
    public String toString() {
        return "MyCallable [ name = " + name + " ]";
    }
}
